package com.demo.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <h3>mq-demo</h3>
 * <p></p>
 *
 * @author : zhengyue
 * @date : 2023/11/3 9:27
 **/
@Configuration
public class FanoutConfiguration {
    @Bean
    public FanoutExchange fanoutExchange() {
        // 方案1
        // return ExchangeBuilder.fanoutExchange("apitest.fanout").build();
        // 方案2
        return new FanoutExchange("apitest.fanout");
    }

    @Bean
    public Queue fanoutQueue1() {
        // 方案 1
        // return QueueBuilder.durable("apitest.fanout"); // 持久化
        // 方案 2 默认持久化
        return new Queue("apitest.fanout.queue1");
    }

    @Bean
    public Binding fanoutBinding(Queue fanoutQueue1, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }

    @Bean
    public Queue fanoutQueue2() {
        // 方案 1
        // return QueueBuilder.durable("apitest.fanout"); // 持久化
        // 方案 2 默认持久化
        return new Queue("apitest.fanout.queue2");
    }

    @Bean
    public Binding fanoutBinding2() {
        return BindingBuilder.bind(fanoutQueue2()).to(fanoutExchange());
    }
}
